package com.davidniu.lesson03;

import com.davidniu.lesson02.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

public class TestDelete {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;

        try {
            conn = JdbcUtils.getConnection();
            //使用?占位符代替参数
            String sql =  "DELETE FROM users WHERE `id` =? ";
            stmt = conn.prepareStatement(sql);//预编译sql,先写sql,不执行
            //手动给参数赋值
            stmt.setInt(1, 4);

            //执行
            int i = stmt.executeUpdate();
            if(i>0) {
                System.out.println("删除成功！");
            }
        } catch(SQLException e){
            e.printStackTrace();
        } finally {
            JdbcUtils.release(conn, stmt, rs);
        }
    }
}
